﻿@model SMECustomerWebsite.Models.ViewModels.CustomerManager.CustomerPortfolioViewModel

@Html.Action("CustInfo", "System")
<!-- start accordion -->
<div class="row">
    <div class="col-md-12">
        <div class="x_panel">
            <div class="x_title">
                <div class="col-lg-8 col-md-9 col-sm-8">
                    @Html.Action("SubMenuAlertCust", "System")
                    <h2>@SMECustomerWebsite.Core.Resources.Resource.AlertGeneral.ToUpper()</h2>
                </div>
                <ul class="nav navbar-right panel_toolbox">
                    @Html.Action("BusinessDateInfo", "System", new { name = "TBL_CM_ALERT_LIMIT" })
                    <li>
                        <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                @switch (Model.CurrentUser.GroupIdentifier)
                {
                    case "1":
                        <table id="cm-alert-loanmatdt" class="table custom_table table-bordered table-striped jambo_table">
                            <thead class="headings">
                                <tr>
                                    <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper()</th>
                                    <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                    <th class="column-title" rowspan="2">DAO</th>
                                    <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                    <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                    <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                    <th class="column-title" colspan="4">@SMECustomerWebsite.Core.Resources.Resource.AlertMaturity.ToUpper()</th>
                                    <th class="column-title" colspan="2">@SMECustomerWebsite.Core.Resources.Resource.AlertBadbank.ToUpper()</th>
                                    <th class="column-title" rowspan="2">CASA GIẢM</th>
                                    <th class="column-title" rowspan="2">DỰ ĐOÁN NGỦ QUÊN</th>
                                </tr>
                                <tr>
                                    <th class="column-title">CHO VAY</th>
                                    <th class="column-title">HUY ĐỘNG</th>
                                    <th class="column-title">BẢO LÃNH</th>
                                    <th class="column-title">HẠN MỨC</th>
                                    <th class="column-title">CHO VAY</th>
                                    <th class="column-title">THẺ</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                        break;
                    case "2":
                    <table id="cm-alert-loanmatdt" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                <th class="column-title" rowspan="2">DAO</th>
                                <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title" colspan="4">@SMECustomerWebsite.Core.Resources.Resource.AlertMaturity.ToUpper()</th>
                                <th class="column-title" colspan="2">@SMECustomerWebsite.Core.Resources.Resource.AlertBadbank.ToUpper()</th>
                                <th class="column-title" rowspan="2">CASA GIẢM</th>
                                <th class="column-title" rowspan="2">DỰ ĐOÁN NGỦ QUÊN</th>
                            </tr>
                            <tr>
                                <th class="column-title">CHO VAY</th>
                                <th class="column-title">HUY ĐỘNG</th>
                                <th class="column-title">BẢO LÃNH</th>
                                <th class="column-title">HẠN MỨC</th>
                                <th class="column-title">CHO VAY</th>
                                <th class="column-title">THẺ</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "3":
                    <table id="cm-alert-loanmatdt" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title" rowspan="2">DAO</th>
                                <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title" colspan="4">@SMECustomerWebsite.Core.Resources.Resource.AlertMaturity.ToUpper()</th>
                                <th class="column-title" colspan="2">@SMECustomerWebsite.Core.Resources.Resource.AlertBadbank.ToUpper()</th>
                                <th class="column-title" rowspan="2">CASA GIẢM</th>
                                <th class="column-title" rowspan="2">DỰ ĐOÁN NGỦ QUÊN</th>
                            </tr>
                            <tr>
                                <th class="column-title">CHO VAY</th>
                                <th class="column-title">HUY ĐỘNG</th>
                                <th class="column-title">BẢO LÃNH</th>
                                <th class="column-title">HẠN MỨC</th>
                                <th class="column-title">CHO VAY</th>
                                <th class="column-title">THẺ</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "4":
                    <table id="cm-alert-loanmatdt" class="table custom_table table-bordered table-striped jambo_table">
                        <thead class="headings">
                            <tr>
                                <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.CifHeader</th>
                                <th class="column-title" rowspan="2">@SMECustomerWebsite.Core.Resources.Resource.NameHeader</th>
                                <th class="column-title" colspan="4">@SMECustomerWebsite.Core.Resources.Resource.AlertMaturity.ToUpper()</th>
                                <th class="column-title" colspan="2">@SMECustomerWebsite.Core.Resources.Resource.AlertBadbank.ToUpper()</th>
                                <th class="column-title" rowspan="2">CASA GIẢM</th>
                                <th class="column-title" rowspan="2">DỰ ĐOÁN NGỦ QUÊN</th>
                            </tr>
                            <tr>
                                <th class="column-title">CHO VAY</th>
                                <th class="column-title">HUY ĐỘNG</th>
                                <th class="column-title">BẢO LÃNH</th>
                                <th class="column-title">HẠN MỨC</th>
                                <th class="column-title">CHO VAY</th>
                                <th class="column-title">THẺ</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    default:
                        break;
                }
            </div>
        </div>
    </div>
</div>

@section scripts
{
    <script src="~/Scripts/custom_search_table.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="~/scripts/datepicker/moment/moment.min.js"></script>
    <script src="~/scripts/datepicker/datepicker/daterangepicker.js"></script>
    <script src="/scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var lcColumn = [{ "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                            { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                            { "sName": "DATE OPEN CIF", "className": 'column-title', "bSortable": false },
                            { "sName": "NAME", "className": 'column-title', "bSortable": false },
                            { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                            { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                            { "sName": "DATE OPEN CIF", "className": 'column-title', "bSortable": false },
                            { "sName": "INFO", "className": 'column-title', "bSortable": false }]
            var lcLenCol = 2;
            var lcCifCol = 0;
            var rowsGroup= [0, 1, 2, 3];
            switch (@Model.CurrentUser.GroupIdentifier) {
                case 1:
                    lcColumn = [{ "sName": "REGION", "bSortable": false },
                                { "sName": "BRANCH", "bSortable": false },
                                { "sName": "DAO", "bSortable": false },
                                { "sName": "MSBO", "bSortable": false },
                                { "sName": "CIF", "bSortable": false },
                                { "sName": "NAME", "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "DATE OPEN CIF", "className": 'column-title', "bSortable": false },
                                { "sName": "NAME", "className": 'column-title', "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "DATE OPEN CIF", "className": 'column-title', "bSortable": false },
                                { "sName": "INFO", "className": 'column-title', "bSortable": false }];
                    lcLenCol = 6;
                    lcCifCol = 4;
                    break;
                case 2:
                    lcColumn = [{ "sName": "BRANCH", "bSortable": false },
                                { "sName": "DAO", "bSortable": false },
                                { "sName": "MSBO", "bSortable": false },
                                { "sName": "CIF", "bSortable": false },
                                { "sName": "NAME", "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "DATE OPEN CIF", "className": 'column-title', "bSortable": false },
                                { "sName": "NAME", "className": 'column-title', "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "DATE OPEN CIF", "className": 'column-title', "bSortable": false },
                                { "sName": "INFO", "className": 'column-title', "bSortable": false }];
                    lcLenCol = 5;
                    lcCifCol = 3;
                    break;
                case 3:
                    lcColumn = [{ "sName": "DAO", "bSortable": false },
                                { "sName": "MSBO", "bSortable": false },
                                { "sName": "CIF", "bSortable": false },
                                { "sName": "VPB INDUSTRY", "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "DATE OPEN CIF", "className": 'column-title', "bSortable": false },
                                { "sName": "NAME", "className": 'column-title', "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "VPB INDUSTRY", "className": 'column-title', "bSortable": false },
                                { "sName": "DATE OPEN CIF", "className": 'column-title', "bSortable": false },
                                { "sName": "INFO", "className": 'column-title', "bSortable": false }];
                    lcLenCol = 4;
                    lcCifCol = 2;
                    break;
                default:
                    break;
            }

            var tableloanmatdt = $('#cm-alert-loanmatdt').DataTable({
                "order": [[0, 'asc']],
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 10,
                rowsGroup: rowsGroup,
                "sAjaxSource": '@Url.Action("AlertGeneralData", "CustomerAlert")',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "simple_numbers",//"full_numbers",
                "aoColumns":lcColumn,
                "aoColumnDefs": [{
                    "aTargets": [lcLenCol],
                    "mRender": function (data) {
                        if (data == '') {
                            return '';
                        } else {
                            return '<a href="/CustomerAlert/alertloanmaturity" style="color:green;"><i class="fa fa-check text-danger"></i></a>';
                        }
                    }
                },{
                    "aTargets": [lcLenCol+1],
                    "mRender": function (data) {
                        if (data == '') {
                            return data;
                        } else {
                            return '<a href="/CustomerAlert/AlertDepositMaturity" style="color:green;"><i class="fa fa-check text-danger"></i></a>';
                        }
                    }
                },{
                    "aTargets": [lcLenCol+2],
                    "mRender": function (data) {
                        if (data == '') {
                            return data;
                        } else {
                            return '<a href="/CustomerAlert/AlertBLMaturity" style="color:green;"><i class="fa fa-check text-danger"></i></a>';
                        }
                    }
                },{
                    "aTargets": [lcLenCol+3],
                    "mRender": function (data) {
                        if (data == '') {
                            return data;
                        } else {
                            return '<a href="/CustomerAlert/AlertLimitMaturity" style="color:green;"><i class="fa fa-check text-danger"></i></a>';
                        }
                    }
                },{
                    "aTargets": [lcLenCol+4],
                    "mRender": function (data) {
                        if (data == '') {
                            return data;
                        } else {
                            return '<a href="/CustomerAlert/AlertOverdueDate" style="color:green;"><i class="fa fa-check text-danger"></i></a>';
                        }
                    }
                },{
                    "aTargets": [lcLenCol+5],
                    "mRender": function (data) {
                        if (data == '') {
                            return data;
                        } else {
                            return '<a href="/CustomerAlert/AlertCardOverdue" style="color:green;"><i class="fa fa-check text-danger"></i></a>';
                        }
                    }
                },{
                    "aTargets": [lcLenCol+6],
                    "mRender": function (data) {
                        if (data == '') {
                            return data;
                        } else {
                            return '<a href="/CustomerAlert/alertcurrentaccount" style="color:green;"><i class="fa fa-check text-danger"></i></a>';
                        }
                    }
                },{
                    "aTargets": [lcLenCol+7],
                    "mRender": function (data) {
                        if (data == '') {
                            return data;
                        } else {
                            return '<a href="/CustomerAlert/alertcustinactive" style="color:green;"><i class="fa fa-check text-danger"></i></a>';
                        }
                    }
                }],
                initComplete: function () {
                    this.api().columns().every(function () {
                        var column = this;
                        switch (column.context[0].aoHeader[0][column.index()].cell.innerText) {
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper())':
                                createFilterRegion(column, '@SMECustomerWebsite.Core.Resources.Resource.Zone');
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper())':
                                createFilterBranch(column);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.DateMatdtHeader.ToUpper())':
                                createFilterDate(column, moment(), moment().subtract(-29, 'days'))
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader.ToUpper())':
                                createFilterMSBOName(column, 1);
                                break;
                            case 'DAO':
                                createFilterMSBOName(column, 2);
                                break;
                            default:
                                if (column.index() < lcLenCol) {
                                    var select = $('<input type="text" class="filtet-table">')
                                                            .appendTo($(column.header()))
                                                            .on('keyup change', function () {
                                                                column.search(this.value).draw();
                                                            });
                                }
                                break;
                        }
                    });
                },
                "drawCallback": function (settings) {
                    $('table.custom_table th').removeClass().addClass('column-title');
                }
            });
        })
    </script>
}
